package com.wocao.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wocao.entity.ReqBody;
import com.wocao.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wocao.entity.SysRole;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 * 角色信息表 Mapper 接口
 * </p>
 *
 * @author Cwj
 * @since 2023-11-21
 */
@Mapper
public interface SysRoleMapper extends BaseMapper<SysRole> {

    //分页查询
//    @Select("SELECT * FROM `sys_role` where del_flag = 0 ORDER BY role_sort asc ")
    Page<SysRole> selectAllPage(Page page,@Param("reqBody") ReqBody reqBody);

    //打开状态
    @Select("UPDATE sys_role set `status` = 0 where role_id = #{roleId}")
    void openStatus(long roleId);

    //关闭状态
    @Select("UPDATE sys_role set `status` = 1 where role_id = #{roleId}")
    void closeStatus(long roleId);

    //给角色菜单关联表添加
    void addRoleMenu(@Param("roleId") long roleId,@Param("menuIds") Object[] menuIds);

    //通过角色Id查询所用有的菜单
    @Select("SELECT menu_id FROM `sys_role_menu` where role_id = #{roleId} ")
    List<Long> selectMenuIdsByRoleId(long roleId);

    //根据角色id删除所有用的菜单id
    @Delete("DELETE from sys_role_menu where role_id = #{roleId} ")
    void deleteMenuIdsByRoleId(long roleId);

    //删除某角色（实际为把删除状态改为1）
    @Update("UPDATE sys_role set del_flag = 2 where role_id = #{roleId} ")
    void deleteRole(long roleId);

    //批量删除
    void deleteRoles(Object[] roleIds);

    //修改数据权限
    @Update("UPDATE sys_role set data_scope = #{dataScope} where role_id= #{roleId}")
    void editDataScope(String dataScope,long roleId);

}
